import createAxios from './axois'
import { BaseRequest, BaseResponse, UpdateServiceReq } from '@/types/request'
import {
  DailyShift,
  ShiftItem,
  AdvisorShiftItem,
  DatePeriod,
  PerformanceItem,
  StarItem,
  AdvisorItem,
  GradeItem,
  SalaryItem
} from '@/types/common'
const request = createAxios()

export const loginLark = (params: { code: string }) => {
  return request.get('/login/lark', { params })
}
export const loginToken = (params: { code: string }) => {
  return request.get('/login/token', { params })
}

// shift
export const getShiftList = (params: BaseRequest): Promise<BaseResponse<ShiftItem[]>> => {
  return request.get('/shift/list', { params })
}

export const addShift = (data: Omit<ShiftItem, 'id'>) => {
  return request.post('/shift/add', data)
}

export const editShift = (data: Pick<ShiftItem, 'id'> & Partial<Omit<ShiftItem, 'id'>>) => {
  return request.post('/shift/update', data)
}

export const deleteShift = (data: Pick<ShiftItem, 'id'>) => {
  return request.delete(`/shift/${data.id}`, { data })
}

// advisor
export const getAdvisorList = (params: BaseRequest): Promise<BaseResponse<AdvisorItem[]>> => {
  return request.get('/advisor/list', { params })
}

// export const addAdvisor = (data) => {
//   return request.post('/advisor/add', data)
// }

export const editAdvisor = (data: Partial<AdvisorItem>) => {
  return request.post(`/advisor/update/${data.advisor_id}`, omit(data, ['advisor_id']))
}

// advisor shift
export const getAdvisorShiftList = (params: BaseRequest & DatePeriod): Promise<BaseResponse<AdvisorShiftItem[]>> => {
  return request.get('/shift/advisor/list', { params })
}

export const addAdvisorShift = (data: Pick<AdvisorShiftItem, 'advisor_id'> & Pick<DailyShift, 'shift_id' | 'date'>) => {
  return request.post('/shift/advisor/add', data)
}

export const addBatchAdvisorShift = (
  data: Pick<AdvisorShiftItem, 'advisor_id'> & Pick<DailyShift, 'shift_id' & DatePeriod>
) => {
  return request.post('/shift/advisor/add/batch', data)
}

export const editAdvisorShift = (data: Pick<DailyShift, 'id'> & Partial<Pick<DailyShift, 'shift_id' | 'status'>>) => {
  return request.post('/shift/advisor/update', data)
}

// grade
export const getGradeList = (params: BaseRequest): Promise<BaseResponse<GradeItem[]>> => {
  return request.get('/grade/list', { params })
}

export const addGrade = (
  data: Omit<GradeItem, 'id' | 'credit_base' | 'performance_base'>
): Promise<BaseResponse<GradeItem[]>> => {
  return request.post('/grade/add', data)
}

export const updateGrade = (
  data: Pick<GradeItem, 'id' | 'credit_up' | 'performance_up'>
): Promise<BaseResponse<GradeItem[]>> => {
  return request.post('/grade/update', data)
}

// performance
export const getPerformancePeriodList = (): Promise<BaseResponse<DatePeriod[]>> => {
  return request.get('/performance/period/list')
}

export const getPerformanceAdvisorList = (params: BaseRequest & DatePeriod): Promise<BaseResponse<PerformanceItem[]>> => {
  return request.get('/performance/advisor/list', { params })
}

// export const addAdvisorPerformance = (data) => {
//   return request.post('/performance/advisor/add', data)
// }

export const performanceAdminScore = (data: DatePeriod & Pick<AdvisorShiftItem, 'advisor_id'> & { score: number }) => {
  return request.post('/performance/admin/score', data)
}

// star相关
export const getStarList = (params: BaseRequest & { star_id?: StarItem['star_id'] }): Promise<BaseResponse<StarItem[]>> => {
  return request.get('/star/list', { params })
}

// 更新服务
export const updateAdvisorStarService = (data: UpdateServiceReq) => {
  return request.post(`/advisor/star/service/update/${data.star_id}`, omit(data, 'star_id'))
}

export const updateRobotService = (data: { star_id: StarItem['star_id']; robot_status: StarItem['robot']['robot_status'] }) => {
  return request.post('/star/robot/switch', data)
}

// 薪资
export const getSalaryAdvisorList = (params: BaseRequest & DatePeriod): Promise<BaseResponse<SalaryItem[]>> => {
  return request.get('/salary/advisor/list', { params })
}

export const updateSalary = (data: Pick<SalaryItem, 'id'> & Partial<SalaryItem>) => {
  return request.post('/salary/update', data)
}
